package com.ruoyi.boat.controller;

import java.util.List;

import com.ruoyi.boat.aop.AvoidDuplicate;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.boat.domain.CtdData;
import com.ruoyi.boat.service.ICtdDataService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * CTD数据Controller
 *
 * @author ruoyi
 * @date 2023-08-09
 */
@Controller
@RequestMapping("/boat/ctdData")
public class CtdDataController extends BaseController {
    private String prefix = "boat/ctdData";

    @Autowired
    private ICtdDataService ctdDataService;

    @RequiresPermissions("boat:ctdData:view")
    @GetMapping()
    public String ctdData() {
        return prefix + "/ctdData";
    }

    /**
     * 查询CTD数据列表
     */
    @RequiresPermissions("boat:ctdData:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CtdData ctdData) {
        startPage();
        List<CtdData> list = ctdDataService.selectCtdDataList(ctdData);
        return getDataTable(list);
    }

    /**
     * 导出CTD数据列表
     */
    @RequiresPermissions("boat:ctdData:export")
    @Log(title = "CTD数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @AvoidDuplicate
    @ResponseBody
    public AjaxResult export(CtdData ctdData) {
        List<CtdData> list = ctdDataService.selectCtdDataList(ctdData);
        ExcelUtil<CtdData> util = new ExcelUtil<CtdData>(CtdData.class);
        return util.exportExcel(list, "CTD数据");
    }

    /**
     * 新增CTD数据
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存CTD数据
     */
    @RequiresPermissions("boat:ctdData:add")
    @Log(title = "CTD数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CtdData ctdData) {
        return toAjax(ctdDataService.insertCtdData(ctdData));
    }

    /**
     * 修改CTD数据
     */
    @RequiresPermissions("boat:ctdData:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        CtdData ctdData = ctdDataService.selectCtdDataById(id);
        mmap.put("ctdData", ctdData);
        return prefix + "/edit";
    }

    /**
     * 修改保存CTD数据
     */
    @RequiresPermissions("boat:ctdData:edit")
    @Log(title = "CTD数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CtdData ctdData) {
        return toAjax(ctdDataService.updateCtdData(ctdData));
    }

    /**
     * 删除CTD数据
     */
    @RequiresPermissions("boat:ctdData:remove")
    @Log(title = "CTD数据", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(ctdDataService.deleteCtdDataByIds(ids));
    }
}
